package dao.impl;

import dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import pojo.User;
import utils.MyBatisUtil;

import java.util.List;

public class UserDaoImpl implements UserDao {

    @Override
    public List<User> findAll(User user,int offset,int pageSize) {
        // 引入mybatis配置文件
        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll(user,offset,pageSize);
    }
    public int addUser(User user)
    {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).addUser(user);
        //提交事务
        session.commit();
        return result;
    }
    @Override
    public User findUserById(int id){
        return MyBatisUtil.getSession().getMapper(UserDao.class).findUserById(id);
    }

    @Override
    public int updateUser(User user)
    {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).updateUser(user);
        //提交事务
        session.commit();
        return result;
    }


    @Override
    public int deleteUserById(int id)
    {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).deleteUserById(id);
        //提交事务
        session.commit();
        return result;
    }

    @Override
    public int count(User user)
    {
        return MyBatisUtil.getSession().getMapper(UserDao.class).count(user);
    }
}